package alg20241125;

public class Text {
    public class ListNode {
     int val;
     ListNode next;
      ListNode() {}
     ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public ListNode reverseList(ListNode head) {
        if(head == null) return null;
        ListNode cur = head;
        ListNode curN = cur.next;
        ListNode prev = null;
        while(cur != null){
            cur.next = prev;
            prev = cur;
            cur = curN;
            if(curN != null) curN = curN.next;
        }
        return prev;
    }
}
